<template>
  <div>
    <el-button type="success" size="small" @click="$refs.role.show()">添加角色</el-button>
    <el-table v-loading="loading" :data="tableData">
      <el-table-column prop="roleName" label="角色名称" width="120">
      </el-table-column>
      <el-table-column prop="desc" label="角色内容" width="250">
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="180">
      </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            @click="$refs.menu.show(scope.row.id)"
            >编辑菜单</el-button
          >
          <el-button type="success" size="mini" @click="$refs.role.show(scope.row)">编辑角色</el-button>
        </template>
      </el-table-column>
    </el-table>
    <role-menu-modal ref="menu" @load="getData"></role-menu-modal>
    <role-modal ref="role" @load="getData"></role-modal>
  </div>
</template>
<script>
import { queryRoles } from "@/api/userManagement/roles";
import roleMenuModal from "./modules/roleMenuModal";
import roleModal from "./modules/roleModal";
export default {
  components: {
    roleMenuModal,
    roleModal
  },
  data() {
    return {
      loading: true,
      tableData: [],
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      this.loading = true;
      queryRoles({}).then((res) => {
        this.loading = false;
        this.tableData = res.data.resultData;
        console.log(res);
      });
    },
  },
};
</script>